package com.fuyun.rpc.client.proxy;

import com.fuyun.rpc.client.config.RpcApplication;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author: zrq1351
 * @date: 2025/2/14
 */
public class ServiceProxyFactory {

	/**
	 * 根据服务类获取代理对象
	 *
	 * @param serviceClass 服务类
	 * @return 代理对象
	 */
	@SuppressWarnings("unchecked")
	public static <T> T getProxy(Class<T> serviceClass, RpcApplication rpcApplication) {
		InvocationHandler proxy = new ServiceProxy(rpcApplication);
		if (rpcApplication.getRpcConfig().getMock()) {
			proxy = new MockDataGeneratorProxy();
		}
		return (T)Proxy.newProxyInstance(serviceClass.getClassLoader(), new Class[] {serviceClass}, proxy);
	}
}